Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
Match "After" if it doesn't have an an -ing word after it

I want to match After if there isn't an -ing word after it (and before a comma). So there shouldn't be an -ing word between After and the comma.

Desired match (bold):

After sitting down, he began to talk.

After finally sitting down, he began to talk.

After he sat down, he began to talk.

I thought this regex would do it:

\bAfter\b.*(?!\w+ing)+,

But it's also matching After if there isn't an -ing word after it:

After sitting down, he began to talk.

After finally sitting down, he began to talk.

After he sat down, he began to talk.

https://regexr.com/683bv

Why is this and how to fix it?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Try this regex

Matches only sentence from After and a comma, where there's no word with -ing after the wo

Just a lazy quantifier to the .+ (which instead of \w+in your regex) does the trick

\bAfter (?!.+?ing).*?,

(And also a lazy quantifier after the second .*, just in case if there's 2 commas in the same sentence)

Output:

img

Regex101 Demo

Tell me if its not working for you...

about 4 years ago · Juan Pablo Isaza Relatório

0

The pattern you tried:

  • Using .* will first match the whole line, then it will backtrack to match the first encountered comma, so it will also match all comma's in between.
  • It can match the first encountered comma because this part (?!\w+ing), asserts that from the current position there are no word chars followed by ing and then match a , But \w does not match a comma so the asserting will always be true.

You can exclude matching a comma in the negative lookahead using a negated character class, and then also match until the first occurrence of a comma afterwards.

\bAfter\b(?![^,\n]*ing)[^,\n]*,

In parts, the pattern matches:

  • \bAfter\b Match the word After between word boundaries
  • (?![^,\n]*ing) Negative lookahead to assert that from the current position there is no occurrence of ing without crossing a comma
  • [^,\n]*, Match optional chars except a comma (or a newline if you don't want to cross lines)

Regex demo

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda